package com.qing.demo.netty.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.Charset;

/**
 * @author caozhipeng
 * @date 2025/7/25
 */
public class MyServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("服务器端接收消息："+msg);
        ByteBuf buf = (ByteBuf) msg;
        byte[] msyBytes = new byte[buf.readableBytes()];
        buf.readBytes(msyBytes);
        System.out.println("服务器端接收消息："+new String(msyBytes, Charset.forName("utf-8")));
    }

}
